package com.zrs.gmall.user.controller;

import com.zrs.gmall.common.result.Result;
import com.zrs.gmall.user.model.LoginVo;
import com.zrs.gmall.user.model.UserInfo;
import com.zrs.gmall.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ZhaoRuiSheng
 * @create 2023/3/7 17:00
 */
@Api(tags = "用户控制器")
@RestController
@RequestMapping("/api/user")
public class PassportController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户登录接口:提供给PC端小程序端使用
     * @param loginVo
     * @return
     */
//    @PostMapping("/passport/login")
//    public Result login(@RequestBody UserInfo loginUser, HttpServletRequest request){
//        return userInfoService.login(loginUser, request);
//    }
    @ApiOperation(value = "用户登录接口:提供给PC端小程序端使用")
    @PostMapping("/passport/login")
    public Result login(@RequestBody LoginVo loginVo, HttpServletRequest request){
        return userInfoService.login(loginVo, request);
    }





    /**
     * 用户退出系统
     * @param token
     * @return
     */
    @ApiOperation(value = "用户退出系统")
    @GetMapping("/passport/logout")
    public Result logout(@RequestHeader("token") String token){
        userInfoService.logout(token);
        return Result.ok();
    }
}
